﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CardsServer.Tools;
using CardsServer.DAL;
namespace CardsServer.WCF
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true, MaxItemsInObjectGraph = int.MaxValue, InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public partial class Service : IService
    {
        private string connStr = MyConfig.getConnection().connstr;
        public string link(string data, string clientVersion)
        {
            return data;
        }
        /// <summary>
        /// 取得帐套连接字符串
        /// </summary>
        /// <param name="accid">帐套ID</param>
        /// <param name="connstr">连接字符串</param>
        /// <returns></returns>
        public string getAccConnStr(int ACID)
        {
            using (
                var ctx =
                    new ACCDataClassesDataContext(MyConfig.getConnection().connstr))
            {
                if (ctx.ACCSET.Count(p => p.ACCSETID == ACID) == 1)
                {
                    ACCSET accinfo = ctx.ACCSET.Single(p => p.ACCSETID == ACID);
                    string server = accinfo.SERVER;
                    string uid = accinfo.UID;
                    string password = accinfo.Password;
                    string database = accinfo.databasename;
                    return string.Format("server={0};database={1};uid={2};pwd={3}", server, database, uid, password);
                }
                else
                {
                    return string.Empty;
                }
            }
        }




    }
}
